package org.asiainfo.system.dubbo;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.asiainfo.common.core.utils.MapstructUtils;
import org.asiainfo.system.api.RemoteLogService;
import org.asiainfo.system.api.domain.bo.RemoteLoginInfoBo;
import org.asiainfo.system.api.domain.bo.RemoteOperationLogBo;
import org.asiainfo.system.domain.bo.SysLoginInfoBo;
import org.asiainfo.system.domain.bo.SysOperationLogBo;
import org.asiainfo.system.service.SysLoginInfoService;
import org.asiainfo.system.service.SysOperationLogService;
import org.springframework.stereotype.Service;

/**
 * 操作日志记录
 *
 * @author dotor-ww
 */
@Service
@DubboService
@RequiredArgsConstructor
@Slf4j
public class RemoteLogServiceImpl implements RemoteLogService {

    private final SysLoginInfoService sysLoginInfoService;

    private final SysOperationLogService sysOperationLogService;

    /**
     * 保存操作日志
     *
     * @param remoteOperationLogBo 日志实体
     */
    @Override
    public void saveLog(RemoteOperationLogBo remoteOperationLogBo) {
        SysOperationLogBo sysOperationLogBo = MapstructUtils.convert(remoteOperationLogBo, SysOperationLogBo.class);
        sysOperationLogService.insertByBo(sysOperationLogBo);
    }

    /**
     * 保存登录日志
     *
     * @param remoteLoginInfoBo 访问实体
     */
    @Override
    public void saveLoginInfo(RemoteLoginInfoBo remoteLoginInfoBo) {
        SysLoginInfoBo sysLoginInfoBo = MapstructUtils.convert(remoteLoginInfoBo, SysLoginInfoBo.class);
        sysLoginInfoService.insertByBo(sysLoginInfoBo);
    }
}
